package com.ruoyi.web.controller.process;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.process.domain.WorkRemosproutiller;
import com.ruoyi.process.service.IWorkRemosproutillerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 除萌蘖管理Controller
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@RestController
@RequestMapping("/process/remosproutiller")
public class WorkRemosproutillerController extends BaseController
{
    @Autowired
    private IWorkRemosproutillerService workRemosproutillerService;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询除萌蘖管理列表
     */
    @PreAuthorize("@ss.hasPermi('process:remosproutiller:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkRemosproutiller workRemosproutiller)
    {
//        startPage();
//        List<WorkRemosproutiller> list=null;
//        SysUser user = tokenService.getLoginUser(ServletUtils.getRequest()).getUser();
//        List<SysRole> roles = user.getRoles();
//        for (SysRole role : roles) {
//            if ("普通角色".equals(role.getRoleName()) || "片区主管".equals(role.getRoleName()) || "棚长".equals(role.getRoleName()) || "棚员".equals(role.getRoleName())) {
//                list = workRemosproutillerService.selectWorkRemosproutillerByuserId(user.getUserId());
//            } else
//                list = workRemosproutillerService.selectWorkRemosproutillerList(workRemosproutiller);
//        }
//        return getDataTable(list);
        startPage();
        List<WorkRemosproutiller> list = workRemosproutillerService.selectWorkRemosproutillerList(workRemosproutiller);
        return getDataTable(list);
    }

    /**
     * 导出除萌蘖管理列表
     */
    @PreAuthorize("@ss.hasPermi('process:remosproutiller:export')")
    @Log(title = "除萌蘖管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkRemosproutiller workRemosproutiller)
    {
        List<WorkRemosproutiller> list=new ArrayList();
        //通过id来取
        Long a[]=workRemosproutiller.getWorkRemosproutillerIds();
        for(int i=0;i<a.length;i++) {
            WorkRemosproutiller list1 = workRemosproutillerService.selectWorkRemosproutillerById(a[i]);
            list.add(list1);
        }

        ExcelUtil<WorkRemosproutiller> util = new ExcelUtil<WorkRemosproutiller>(WorkRemosproutiller.class);
        return util.exportExcel(list, "除萌蘖管理数据");
    }

    /**
     * 获取除萌蘖管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('process:remosproutiller:query')")
    @GetMapping(value = "/{workRemosproutillerId}")
    public AjaxResult getInfo(@PathVariable("workRemosproutillerId") Long workRemosproutillerId)
    {
        return AjaxResult.success(workRemosproutillerService.selectWorkRemosproutillerById(workRemosproutillerId));
    }

    /**
     * 新增除萌蘖管理
     */
    @PreAuthorize("@ss.hasPermi('process:remosproutiller:add')")
    @Log(title = "除萌蘖管理", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type= InjectType.Insert)
    public AjaxResult add(@RequestBody WorkRemosproutiller workRemosproutiller)
    {
        return toAjax(workRemosproutillerService.insertWorkRemosproutiller(workRemosproutiller));
    }

    /**
     * 修改除萌蘖管理
     */
    @PreAuthorize("@ss.hasAnyPermi('process:remosproutiller:edit,process:remosproutiller:permit')")
    @Log(title = "除萌蘖管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type= InjectType.Update)
    public AjaxResult edit(@RequestBody WorkRemosproutiller workRemosproutiller)
    {
        return toAjax(workRemosproutillerService.updateWorkRemosproutiller(workRemosproutiller));
    }

    /**
     * 删除除萌蘖管理
     */
    @PreAuthorize("@ss.hasPermi('process:remosproutiller:remove')")
    @Log(title = "除萌蘖管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{workRemosproutillerIds}")
    public AjaxResult remove(@PathVariable Long[] workRemosproutillerIds)
    {
        return toAjax(workRemosproutillerService.deleteWorkRemosproutillerByIds(workRemosproutillerIds));
    }
}
